package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.ProductTypeDao;
import ysq.xyg.model.ProductType;
import ysq.xyg.service.ProductTypeService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-04-19 14:11
 **/
@Service("productTypeService")
public class ProductTypeServiceImpl extends BaseServiceImpl<ProductType> implements ProductTypeService {
    @Resource
    private ProductTypeDao productTypeDao;
    @Autowired
    public void setProductTypeDao(ProductTypeDao productTypeDao) {
        this.baseDao = productTypeDao;
    }

    //分页查询
    public PageInfo<ProductType> pageInfo(ProductType productType, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        //通用Example查询
        Example example = new Example(ProductType.class);
        Example.Criteria criteria = example.createCriteria();
        if(productType!=null){
            if(StringUtil.isNotEmpty(productType.getName())){
                criteria.andLike("name",productType.getName());
            }
        }
        List<ProductType> list=productTypeDao.selectByExample(example);

        return new PageInfo<ProductType>(list);
    }


    public ProductType selectById(String id) {
        ProductType productType=new ProductType();
        productType.setId(id);
        List<ProductType> list=productTypeDao.select(productType);
        if(list!=null && list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }

}
